package com.ht.impl.myactions;

import com.ht.aems.swing.util.MyAction;
import com.ht.impl.ResourceTypeCons;
import com.mxgraph.model.mxCell;
import com.mxgraph.model.mxIGraphModel;
import com.mxgraph.view.mxGraph;
import com.mxgraph.swing.mxGraphComponent;

import java.awt.event.ActionEvent;
import java.util.List;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Dong Shufeng
 *         Date: 2010-8-26
 */
public class HideLine extends MyAction implements ResourceTypeCons {
    static List<mxCell> lines = new ArrayList<mxCell>();
    public void actionPerformed(ActionEvent e) {
        mxGraphComponent component = (mxGraphComponent) e.getSource();
        mxGraph graph = component.getGraph();
        mxIGraphModel model = graph.getModel();
        Object[] cells = graph.getSelectionCells();
        if (cells.length == 0)
            return;
        mxCell cell;
        lines.clear();
        for(Object obj : cells) {
            cell = (mxCell) obj;
            if(cell.isEdge())
                lines.add(cell);
        }
        model.beginUpdate();
        for(mxCell c : lines)
            model.setVisible(c, false);
        model.endUpdate();
    }
}